﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TargetFilter.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Filters.TargetFilter" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Filters
{
    using System;
    using System.Data.Objects;
    using System.Linq;
    using Entities;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Filters.TargetFilter"/> type.
    /// </summary>
    public static class TargetFilter
    {
        /// <summary>
        /// Filters the specified Tag tags.
        /// </summary>
        /// <param name="collection">The Tag tags.</param>
        /// <param name="objectToMatch">The Tag to match.</param>
        /// <returns>List of filtered Tags</returns>
        public static IQueryable<Target> Filter(this IObjectSet<Target> collection, Target objectToMatch)
        {
            return objectToMatch == null ?
                collection :
                from target in collection
                where (objectToMatch.Id == 0 || target.Id == objectToMatch.Id) &&
                (objectToMatch.AccountId == 0 || target.AccountId == objectToMatch.AccountId) &&
                (objectToMatch.Amount == 0 || target.Amount == objectToMatch.Amount) &&
                (objectToMatch.TargetType == 0 || target.TargetType == objectToMatch.TargetType) &&
                (objectToMatch.TagId == 0 || target.TagId == objectToMatch.Id) &&
                (objectToMatch.TargetDate == default(DateTime) || target.TargetDate == objectToMatch.TargetDate) &&
                (objectToMatch.Title == null || target.Title.Equals(objectToMatch.Title, StringComparison.InvariantCultureIgnoreCase))
                select target;
        }
    }
}